package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> getAllList() {
        return nursingLevelMapper.findAll();
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto){
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public PageResponse getByPage(String name, Integer pageNum, Integer pageSize, Integer status){

        PageHelper.startPage(pageNum,pageSize);

        Page<NursingLevelVo> nursingLevelVos = nursingLevelMapper.selectByPage(name, status);
        return PageResponse.of(nursingLevelVos,NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo getById(Integer id){
        return nursingLevelMapper.findById(id);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto){
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void deleteById(Integer id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void openAndClose(Integer id, @PathVariable Integer status){
        nursingLevelMapper.statusControl(id,status);
    }


}
